package com.fs;

import org.junit.Test;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Iterator;
import java.util.Set;

/**
 * @author shuai.fang
 * @date：2017-04-10
 * @description：
 */
public class HibernateValidatorTest {

	@Test
	public void test01() {

		Person person = new Person();
		person.setName("f");

		ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
		Validator validator = validatorFactory.getValidator();

		Set<ConstraintViolation<Person>> set = validator.validate(person);
		Iterator<ConstraintViolation<Person>> iterator = set.iterator();
		while (iterator.hasNext()) {
			ConstraintViolation<Person> constraintViolation = iterator.next();

			System.out.println(constraintViolation.getMessage());
		}


	}

}
